package com.wan37.logic.chat.service.impl;

import com.wan37.logic.chat.dao.WorldChatDao;
import com.wan37.logic.chat.domain.entity.WorldChatDO;
import com.wan37.logic.chat.domain.vo.ChatVO;
import com.wan37.logic.chat.service.WorldChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : luoyong
 * @date : 2020-07-27 11:13
 **/
@Service("worldChatService")
public class WorldChatServiceImpl implements WorldChatService {

    @Autowired
    private WorldChatDao worldChatDao;

    @Override
    public boolean update(ChatVO chatVO) {
        WorldChatDO worldChatDO = new WorldChatDO(chatVO);
        return worldChatDao.update(worldChatDO);
    }

    @Override
    public boolean save(ChatVO chatVO) {
        WorldChatDO worldChatDO = new WorldChatDO(chatVO);
        return worldChatDao.add(worldChatDO);
    }

    @Override
    public boolean delete(ChatVO chatVO) {
        WorldChatDO worldChatDO = new WorldChatDO(chatVO);
        return worldChatDao.delete(worldChatDO.getId());
    }

    @Override
    public List<ChatVO> getWorldChatDOByUserId(String userId) {
        List<WorldChatDO> worldChatDOList = worldChatDao.getWorldChatByUserId(userId);
        List<ChatVO> chatVOList = null;
        if (worldChatDOList != null) {
            chatVOList = new ArrayList<>();
            for (WorldChatDO worldChatDO : worldChatDOList) {
                chatVOList.add(new ChatVO(worldChatDO));
            }
        }
        return chatVOList;
    }

    @Override
    public List<ChatVO> getAllWorldChatDO() {
        List<WorldChatDO> worldChatDOList = worldChatDao.getAll();
        List<ChatVO> chatVOList = null;
        if (worldChatDOList != null) {
            chatVOList = new ArrayList<>();
            for (WorldChatDO worldChatDO : worldChatDOList) {
                chatVOList.add(new ChatVO(worldChatDO));
            }
        }
        return chatVOList;
    }
}
